home *** CD-ROM | disk | FTP | other *** search
- FILEBUF(3C) Last changed: 1-14-99
-
-
- NNAAMMEE
- ffiilleebbuuff - Buffer for file I/O
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<iioossttrreeaamm..hh>>
-
- ttyyppeeddeeff lloonngg ssttrreeaammooffff,, ssttrreeaammppooss;;
- ccllaassss iiooss {{
- ppuubblliicc::
- eennuumm sseeeekk__ddiirr {{ bbeegg,, ccuurr,, eenndd }};;
- eennuumm ooppeenn__mmooddee {{ iinn,, oouutt,, aattee,, aapppp,, ttrruunncc,, nnooccrreeaattee,, nnoorreeppllaaccee }}
- ;;
- //ee aanndd lloottss ooff ootthheerr ssttuuffff,, sseeee iiooss((33CC)) ......
- }} ;;
-
- ##iinncclluuddee <<ffssttrreeaamm..hh>>
-
- ccllaassss ffiilleebbuuff :: ppuubblliicc ssttrreeaammbbuuff {{
- ppuubblliicc::
- ssttaattiicc ccoonnsstt iinntt ooppeennpprroott ;; //** ddeeffaauulltt pprrootteeccttiioonn ffoorr ooppeenn **//
-
- ffiilleebbuuff(()) ;;
- ~~ffiilleebbuuff(()) ;;
- ffiilleebbuuff((iinntt dd));;
- ffiilleebbuuff((iinntt dd,, cchhaarr** pp,, iinntt lleenn)) ;;
-
- ffiilleebbuuff** aattttaacchh((iinntt dd)) ;;
- ffiilleebbuuff** cclloossee(());;
- iinntt ffdd(());;
- iinntt iiss__ooppeenn(());;
- ffiilleebbuuff** ooppeenn((cchhaarr **nnaammee,, iinntt oommooddee,, iinntt pprroott==ooppeennpprroott)) ;;
- ssttrreeaammppooss sseeeekkooffff((ssttrreeaammooffff,, sseeeekk__ddiirr,, iinntt oommooddee)) ;;
- ssttrreeaammppooss sseeeekkppooss((ssttrreeaammppooss,, iinntt oommooddee)) ;;
- ssttrreeaammbbuuff** sseettbbuuff((cchhaarr** pp,, iinntt lleenn)) ;;
- iinntt ssyynncc(()) ;;
- }};;
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- A ffiilleebbuuff specializes a ssttrreeaammbbuuff to use a file as a source or sink of
- characters. Characters are consumed by doing writes to the file, and
- are produced by doing reads. When the file is seekable, a ffiilleebbuuff
- allows seeks. At least 4 characters of putback are guaranteed. When
- the file permits reading and writing, the ffiilleebbuuff permits both storing
- and fetching. No special action is required between gets and puts
- (unlike stdio). A ffiilleebbuuff that is connected to a file descriptor is
- said to be open. Files are opened with a protection mode of ooppeennpprroott
- (0644), which is the default.
-
- The _r_e_s_e_r_v_e _a_r_e_a (or buffer, see ssbbuuff..ppuubb(3C) and ssbbuuff..pprroott(3C)) is
- allocated automatically if one is not specified explicitly with a
- constructor or a call to sseettbbuuff(()). A ffiilleebbuuff can also be made
- uunnbbuuffffeerreedd with certain arguments to the constructor or sseettbbuuff(()), in
- which case a system call is made for each character that is read or
- written. The ggeett and ppuutt pointers into the reserve area are
- conceptually tied together; they behave as a single pointer.
- Therefore, the following descriptions refer to a single get/put
- pointer.
-
- In the following descriptions, the following assumptions are made:
-
- * _f is a ffiilleebbuuff.
-
- * _p_f_b is a ffiilleebbuuff**.
-
- * _p_s_b is a ssttrreeaammbbuuff**.
-
- * _i, _d, _l_e_n, and _p_r_o_t are iinntts.
-
- * _n_a_m_e and _p_t_r are cchhaarr**s.
-
- * _m_o_d_e is an iinntt representing an ooppeenn__mmooddee.
-
- * _o_f_f is a ssttrreeaammooffff.
- - _p and _p_o_s are ssttrreeaammppooss's.
- - _d_i_r is a sseeeekk__ddiirr.
-
- Constructors:
-
- ffiilleebbuuff(())
- Constructs an initially closed ffiilleebbuuff.
-
- ffiilleebbuuff((_d))
- Constructs a ffiilleebbuuff connected to file descriptor _d.
-
- ffiilleebbuuff((_d,, _p,, _l_e_n))
- Constructs a ffiilleebbuuff connected to file descriptor _d and
- initialized to use the reserve area starting at _p and containing
- _l_e_n bytes. If _p is null or _l_e_n is zero or less, the ffiilleebbuuff will
- be unbuffered.
-
- Members:
-
- _p_f_b==_f..aattttaacchh((_d))
- Connects _f to an open file descriptor, _d. aattttaacchh(()) normally
- returns &&_f,, bbuutt rreettuurrnnss 00 iiff _f iiss aallrreeaaddyy ooppeenn..
-
- _p_f_b==_f..cclloossee(())
- Flushes any waiting output, closes the file descriptor, and
- disconnects _f. Unless an error occurs, _f's error state will be
- cleared. cclloossee(()) returns &&_f uunnlleessss eerrrroorrss ooccccuurr,, iinn wwhhiicchh ccaassee
- iitt rreettuurrnnss 00.. EEvveenn iiff eerrrroorrss ooccccuurr,, cclloossee(()) lleeaavveess tthhee ffiillee
- ddeessccrriippttoorr aanndd _f cclloosseedd..
-
- _i==_f..ffdd(())
- Returns _i, the file descriptor _f is connected to. If _f is
- closed, _i is EEOOFF.
-
- _i==_f..iiss__ooppeenn(())
- Returns non-zero when _f is connected to a file descriptor, and
- zero otherwise.
-
- _p_f_b==_f..ooppeenn((_n_a_m_e,, _m_o_d_e,, _p_r_o_t))
- Opens file _n_a_m_e and connects _f to it. If the file does not
- already exist, an attempt is made to create it with protection
- mode _p_r_o_t, unless iiooss::::nnooccrreeaattee is specified in _m_o_d_e. By
- default, _p_r_o_t is ffiilleebbuuff::::ooppeennpprroott, which is 0644. Failure
- occurs if _f is already open. ooppeenn(()) normally returns &&_f,, bbuutt iiff
- aann eerrrroorr ooccccuurrss iitt rreettuurrnnss 00.. TThhee mmeemmbbeerrss ooff ooppeenn__mmooddee aarree bbiittss
- tthhaatt mmaayy bbee oorr''eedd ttooggeetthheerr.. ((BBeeccaauussee tthhee oorr''iinngg rreettuurrnnss aann iinntt,,
- ooppeenn(()) ttaakkeess aann iinntt rraatthheerr tthhaann aann ooppeenn__mmooddee aarrgguummeenntt..)) TThhee
- mmeeaanniinnggss ooff tthheessee bbiittss iinn _m_o_d_e aarree ddeessccrriibbeedd iinn ddeettaaiill iinn
- ffssttrreeaamm((33CC))..
-
- _p==_f..sseeeekkooffff((_o_f_f,, _d_i_r,, _m_o_d_e))
- Moves the get/put pointer as designated by _o_f_f and _d_i_r. It may
- fail if the file that _f is attached to does not support seeking,
- or if the attempted motion is otherwise invalid (such as
- attempting to seek to a position before the beginning of file).
- _o_f_f is interpreted as a count relative to the place in the file
- specified by _d_i_r as described in ssbbuuff..ppuubb(3C). _m_o_d_e is ignored.
- sseeeekkooffff(()) returns _p, the new position, or EEOOFF if a failure
- occurs. The position of the file after a failure is undefined.
-
- _p==_f..sseeeekkppooss((_p_o_s,, _m_o_d_e))
- Moves the file to a position _p_o_s as described in ssbbuuff..ppuubb(3C).
- _m_o_d_e is ignored. sseeeekkppooss(()) normally returns _p_o_s, but on failure
- it returns EEOOFF.
-
- _p_s_b==_f..sseettbbuuff((_p_t_r,, _l_e_n))
- Sets up the reserve area as _l_e_n bytes beginning at _p_t_r. If _p_t_r
- is null or _l_e_n is less than or equal to 0, _f will be unbuffered.
- sseettbbuuff(()) normally returns &&_f.. HHoowweevveerr,, iiff _f iiss ooppeenn aanndd aa bbuuffffeerr
- hhaass bbeeeenn aallllooccaatteedd,, nnoo cchhaannggeess aarree mmaaddee ttoo tthhee rreesseerrvvee aarreeaa oorr ttoo
- tthhee bbuuffffeerriinngg ssttaattuuss,, aanndd sseettbbuuff(()) rreettuurrnnss 00..
-
- _i==_f..ssyynncc(())
- Attempts to force the state of the get/put pointer of f to agree
- (be synchronized) with the state of the file _f..ffdd(()). _T_h_i_s _m_e_a_n_s
- _i_t _m_a_y _w_r_i_t_e _c_h_a_r_a_c_t_e_r_s _t_o _t_h_e _f_i_l_e _i_f _s_o_m_e _h_a_v_e _b_e_e_n _b_u_f_f_e_r_e_d
- _f_o_r _o_u_t_p_u_t _o_r _a_t_t_e_m_p_t _t_o _r_e_p_o_s_i_t_i_o_n (_s_e_e_k) _t_h_e _f_i_l_e _i_f _c_h_a_r_a_c_t_e_r_s
- _h_a_v_e _b_e_e_n _r_e_a_d _a_n_d _b_u_f_f_e_r_e_d _f_o_r _i_n_p_u_t. _N_o_r_m_a_l_l_y, ssyynncc(()) _r_e_t_u_r_n_s
- _0, _b_u_t _i_t _r_e_t_u_r_n_s EEOOFF _i_f _s_y_n_c_h_r_o_n_i_z_a_t_i_o_n _i_s _n_o_t _p_o_s_s_i_b_l_e.
-
- _S_o_m_e_t_i_m_e_s _i_t _i_s _n_e_c_e_s_s_a_r_y _t_o _g_u_a_r_a_n_t_e_e _t_h_a_t _c_e_r_t_a_i_n _c_h_a_r_a_c_t_e_r_s
- _a_r_e _w_r_i_t_t_e_n _t_o_g_e_t_h_e_r. _T_o _d_o _t_h_i_s, _t_h_e _p_r_o_g_r_a_m _s_h_o_u_l_d _u_s_e
- sseettbbuuff(()) (_o_r _a _c_o_n_s_t_r_u_c_t_o_r) _t_o _g_u_a_r_a_n_t_e_e _t_h_a_t _t_h_e _r_e_s_e_r_v_e _a_r_e_a _i_s
- _a_t _l_e_a_s_t _a_s _l_a_r_g_e _a_s _t_h_e _n_u_m_b_e_r _o_f _c_h_a_r_a_c_t_e_r_s _t_h_a_t _m_u_s_t _b_e
- _w_r_i_t_t_e_n _t_o_g_e_t_h_e_r. _I_t _c_a_n _t_h_e_n _c_a_l_l ssyynncc(()), _t_h_e_n _s_t_o_r_e _t_h_e
- _c_h_a_r_a_c_t_e_r_s, _t_h_e_n _c_a_l_l ssyynncc(()) _a_g_a_i_n.
-
- NNOOTTEESS
- There is no way to force atomic reads.
-
- ffiilleebbuuff does not report failures of seek (for example, on a tty).
-
- SSEEEE AALLSSOO
- ssbbuuff..ppuubb(3C), ssbbuuff..pprroott(3C), ffssttrreeaamm(3C)
-
- This man page is available only online.
-